Project Overview
I recently completed an optimization project for the Café web
application on AWS. This activity required me to optimize the AWS
resources used to run the Café web application. Specifically, I had to:
-
Uninstall the decommissioned local database from the Café instance to
decrease the instance's storage requirements.
- Change the instance type to T3 micro to reduce costs.
After completing this activity, I was able to:
-
Optimize an Amazon Elastic Compute Cloud (Amazon EC2) instance to
reduce costs.
- Use the AWS Pricing Calculator to estimate AWS service costs.
The business case for this was a new requirement for Café – to optimize
resources to reduce AWS service costs.
After the migration to Amazon Relational Database Service (Amazon RDS)
was completed (an action taken in a prior activity), I identified
optimization opportunities to implement to reduce AWS service costs.
First, I realized that the decommissioned local database could be
uninstalled to reduce the storage requirements of the Café instance. I
also realized that the Café instance could be downsized to a smaller
instance type because the database process was no longer running on it.
Task 1: Optimize the website to reduce costs
Because the local database was migrated to Amazon RDS, I could reduce
AWS service costs by performing the following actions on the Café EC2
instance:
-
Remove the local database from the instance. This action reduced costs
in both CPU and storage utilization.
-
Change the instance type from t3.small to t3.micro. Because the
database process no longer runs on the instance, the smaller instance
type was both effective and also cheaper to run.
In this task, I used the AWS Command Line Interface (AWS CLI) to perform
these actions. I began by opening a Secure Shell (SSH) session to the
Café instance and the CLI Host.
Task 1.1.3: Configure the AWS CLI
Before I could run AWS CLI commands on the instance, I first had to
configure the AWS CLI environment to define the AWS account credentials,
Region name, and output format to use.
I left this terminal window SSH session open to use it later in the
activity.
Task 1.2: Connect to the CLI Host instance by using SSH
-
I followed the same instructions that I used in Task 1.1 to open an
SSH session to a different EC2 instance—the CLI Host instance.
-
I did not close the connection to the CafeInstance, instead, I created
a connection to the CLI Host in a new window (using putty on Windows
or can be done using an additional terminal window on macOS/Linux).
-
I found the CLI Host public IP address in the EC2 console, and by
clicking on the Details drop down menu above the instructions, and
then clicking Show.
-
After connecting, I also configured the AWS CLI client software on the
CLI Host EC2 instance, by running the aws configure command.
Task 1.3: Uninstall MariaDB and resize the instance
-
I stopped the local database and uninstalled it from the Café
instance. In the SSH window for the CafeInstance, I entered:
sudo systemctl stop mariadb sudo yum -y remove mariadb-server
-
When the last command ran successfully, I saw a Complete! message in
the output.
-
I closed the SSH window for the CafeInstance because I no longer
needed it.
-
I determined the Instance ID of the CafeInstance. I switched to the
SSH window for the CLI Host instance and entered:
aws ec2 describe-instances \ --filters "Name=tag:Name,Values=
CafeInstance" \ --query "Reservations[*].Instances[*].InstanceId"
-
I recorded the value returned as:
CafeInstance Instance ID: i-nnnnnnnnnn
-
I stopped the Café instance and changed its instance type to t3.micro.
In the SSH window for the CLI Host instance, I entered:
aws ec2 stop-instances --instance-ids <CafeInstance Instance
ID>
-
In the command, I substituted <CafeInstance Instance ID> with
the value that I recorded earlier.
-
I changed the instance type to t3.micro. In the SSH window for the CLI
Host instance, I entered:
aws ec2 modify-instance-attribute \ --instance-id <CafeInstance
Instance ID> \ --instance-type "{\"Value\": \"t3.micro\"}"
-
In the command, I substituted <CafeInstance Instance ID> with
the value that I recorded earlier.
-
When the command completed successfully, no output was returned.
-
I started the Café instance. In the SSH window for the CLI Host
instance, I entered:
aws ec2 start-instances --instance-ids <CafeInstance Instance
ID>
-
In the command, I substituted <CafeInstance Instance ID> with
the value that I recorded earlier.
-
I checked the current state of the instance, and waited until the
status showed running. In the SSH window for the CLI Host instance, I
entered:
aws ec2 describe-instances \ --instance-ids <CafeInstance
Instance ID> \ --query
"Reservations[*].Instances[*].[InstanceType,PublicDnsName,PublicIpAddress,State.Name]"
-
In the command, I substituted <CafeInstance Instance ID> with
the value that I recorded earlier.
-
The instance took a few moments to reach the running state. I
periodically repeated the command until I could confirm that it was
running. I also recorded the PublicDnsName and PublicIPAddress values
that were returned by the command by using the following format:
Downsized CafeInstance Public DNS Name:
ec2-zzz-zzz-zzz-zzz.eu-west-2.compute.amazonaws.com Downsized
CafeInstance Public IP Address: nnn.nnn.nnn.nnn
Information: Because I restarted the instance, Amazon EC2 assigned a
different Public DNS name and Public IP address to the instance than
what it had before.
I successfully uninstalled the decommissioned local database and
downsized the Café instance.
Task 2: Use the AWS Pricing Calculator to estimate AWS service costs
AWS provides a tool that allows users to estimate the monthly costs of
the AWS services that they use or are planning to use. In this task, I
used the AWS Pricing Calculator to estimate the cost of running the Café
website on AWS before and after EC2 instance optimization. I then
calculated the projected cost savings.
NOTE: The values that I entered into the AWS Pricing Calculator were
simplified to serve the purposes of this exercise. The intent was to
show the basic use of the calculator and highlight the functions that it
provides.
The pricing examples shown in this activity were current as of time of
publishing, April 2020, and is for informational purposes. Refer to the
AWS website for current pricing by service.
Task 2.1: Calculate the costs before optimization
First, I calculated the costs of running the website in its before
optimization topology, that is, on a T3 small instance with a
decommissioned local database still occupying storage space.
Specifically, I used the following service list and configuration to
describe the topology components:
Region: (the region where the CafeInstance EC2 instance is running)
Amazon EC2 instance:
- Instance type: t3.small
- Instance class: On-Demand
- Utilization: 100% per month
- Operating system: Linux
-
Amazon EBS volume: General Purpose SSD (gp2), 40 GB (including 20 GB
occupied by the local database)
Amazon RDS instance:
- Instance class: db.t3.micro
- Engine: MariaDB
- Allocated storage: 20 GB
-
I opened the AWS Pricing Calculator. In a web browser, I went to:
https://calculator.aws
- I clicked on Create estimate.
-
I browsed down and chose Configure in the Amazon EC2 service box.
-
In the Region menu at the top of the page, I selected the region where
the CafeInstance EC2 instance was running. For example, I chose US
East (N. Virginia) if my instances were running in us-east-1.
-
When I was prompted to confirm the region change, I chose Change
Region.
- I chose the Advanced estimate option.
-
In the EC2 instance specifications area, for the Operating system, I
chose Linux
-
In the Workload area:
- I chose Constant usage.
- For Number of instances I chose 1.
-
In the EC2 instances area, in the search box, I searched for and then
selected the t3.small instance type.
-
In the Pricing strategy area, I set the pricing model to On-Demand
-
In the Amazon Elastic Block Storage (EBS) area:
- Storage for each EC2 instance: General Purpose SSD (gp2)
- Storage amount: 40 GB
- Snapshot Frequency: No snapshot storage
- I scrolled to the bottom and selected Add to my estimate.
I had now estimated the cost of the EC2 instance.
Next, I added the RDS instance to my price estimate.
- In the My Estimate page, I clicked Add service.
-
In the Select service page, I located and clicked Configure in the
Amazon RDS for MariaDB service panel.
-
I configured as follows:
-
Region: (chose the same Region I chose for the EC2 instance)
- MariaDB instance specifications: Standard (single-AZ)
- Instance type: searched for and selected db.t3.micro
- Quantity: 1
- Pricing model: On-Demand Instances
- Storage volume: General Purpose SSD (gp2)
- Storage amount: 20 GB per month
- I chose Add to my estimate.
-
The My Estimate page showed a breakdown of the estimated monthly cost
of the AWS services that I configured, and it provided a monthly
total.
- I chose Save and share.
- When prompted, I chose Agree and continue.
-
I chose Copy the public link and pasted the link into another browser
tab.
-
I exported the estimate to a comma-separated values (CSV) file by
choosing Action > Export estimate.
-
In the export dialog window, I clicked OK and saved the file to my
local computer. I opened it to see its contents.
Task 2.2: Calculate the costs after optimization
Next, I calculated the costs of running the website after the Café
instance was optimized. Specifically, I modified the following entries
in the calculator to reflect the effects of the optimization:
Amazon EC2 instance:
- Instance type: t3.micro (Reduced size)
-
Amazon Elastic Block Store (Amazon EBS) General Purpose SSD (gp2), 20
GB (Reduced from 40 GB because the local database was removed)
-
In the https://calculator.aws/#/estimate browser tab, I clicked Edit
next to the Amazon EC2 entry.
-
In the EC2 Instances area, I searched for and selected t3.micro as the
instance type.
-
In the Amazon Elastic Block Storage (EBS) area, I changed the Storage
amount to 20 GB.
-
I scrolled down and clicked Save to see the monthly cost estimate.
-
I exported the estimate to a comma-separated values (CSV) file by
choosing Action > Export estimate.
-
In the export dialog window, I clicked OK and saved the file to my
local computer. I opened it to see its contents.
Task 2.3: Estimate the projected cost savings for Café
Because I calculated the costs of the AWS services that are needed to
run the Café website both before and after I optimized the instance, I
could estimate the overall projected cost savings.
By removing the decommissioned local database and downsizing the Café
instance type, I saved more in AWS service costs.
Martha and Frank were very happy that my initiative resulted in cost
savings for the business.